<?php
/**
 * 后台相关
 * @author fanzhanao
 *
 */
class member_controller_roll extends SnsController{
//	var $right_view = true;
	public function __construct($app, $controller){
		parent::__construct($app, $controller);
		$this->data = Model::factory('member_model_roll');
	}
	
	/**
	 * 添加修改
	 *
	 */
	public function add_action(){
		$args['title']	=	_('title');
		$args['info'] = _('info');
		$args['flag']	=	1;
		$args['id']	=	_('id');
		if($_FILES['imgurl'] && !$_FILES['imgurl']['error']){
			$path = 'rollimg/';
			$filename = md5(CURRENT_TIME.rand(1,10000));
			$rs = cartoon_util_upload::upload_file('imgurl',$path,$filename);
			if($rs['result']){
				$args['imgurl'] = $rs['url'];
			}
		}
		/**
		 * 是否為修改
		 */
		if($args['id']){
			if($this->data->edit($args)){
				$this->ret = self::success();
			}else $this->ret = self::failure('修改失败');
		}else{
			if($this->data->add($args)){
				$this->ret = self::success();
			}
			else{
				$this->ret = self::failure('添加失败');
			}
		}
	}
	
	/**
	 * 删除
	 *
	 */
	public function del_action(){
		$id = _('id');
		if($this->data->remove($id)){
			$this->ret = self::success();
		}else $this->ret = self::failure('删除失败');
	}
}